package com.fyl.ex;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@Component
public class MyHandlerExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
//        ModelAndView modelAndView = new ModelAndView("/index.jsp");
//        return modelAndView;

       // {"code":0,"message":"123","data":"1234"}
        String json = "{\"code\":0,\"message\":\"123\",\"data\":\"1234\"}";
        try {
            httpServletResponse.getWriter().write(json);
        } catch (IOException ex) {
            e.printStackTrace();
        }
        return null;
    }
}
